// import LogUtil from '../utils/LogUtil'
import Service from '../service/RepayService'

export const NameSpace = 'RepayModel'

function createAction(action, payload) {
  return { type: `${NameSpace}/${action}`, payload }
}
export const Actions = {
  asyncActionGetRepayList(params) {
    return createAction('asyncGetRepayList', params)
  },
  asyncActionSetData(params) {
    return createAction('asyncSetData', params)
  },
  asyncActionSetPayUrl(params) {
    return createAction('asyncSetPayUrl', params)
  },
  asyncActionSetOnjString(params) {
    return createAction('asyncSetObjString', params)
  }
}
function actionList(list) {
  return createAction('list', list)
}
function actionData(Data) {
  return createAction('data', Data)
}
function actionUrl(url) {
  return createAction('url', url)
}
function actionResult(stat) {
  return createAction('result', stat);
}
function actionObjString(objString) {
  return createAction('setobjString', objString)
}
export default {
  namespace: NameSpace,
  state: {
    list: null,
    data: null,
    url: null,
    state: 1,
    objString: null
  },
  reducers: {
    list(state, { payload }) {
      return {
        ...state,
        list: payload
      }
    },
    data(state, { payload }) {
      return {
        ...state,
        data: payload
      }
    },
    url(state, { payload }) {
      return {
        ...state,
        url: payload
      }
    },
    setobjString(state, { payload }) {
      return {
        ...state,
        objString: payload
      }
    },
    result(state, { payload }) {
      return {
        ...state,
        state: payload
      }
    },
  },
  asyncTasks: {
    asyncGetRepayList({ dispatch }, { payload }) {
      Service.netGetRepayList(payload).then(res => {
        // dispatch.actionList(res.info)
        // LogUtil.log(res.info);
        if (res.info.length === 0) {
          dispatch(actionResult(0));
        } else {
          dispatch(actionResult(1))
        }
        dispatch(actionList(res.info),

        )
      })
        .catch((err) => {
          dispatch(actionResult(0))

        })
    },
    asyncSetData({ dispatch }, { payload }) {
      dispatch(actionData(payload))
    },
    asyncSetPayUrl({ dispatch }, { payload }) {
      dispatch(actionUrl(payload))
    },
    asyncSetObjString({ dispatch }, { payload }) {
      dispatch(actionObjString(payload))
    }

  }

}

